import 'package:cloud_medicine/components/doctor_list.dart';
import 'package:cloud_medicine/components/post_list.dart';
import 'package:cloud_medicine/pages/edit_post.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class PostPage extends StatefulWidget {
  @override
  _PostPageState createState() => _PostPageState();
}

class _PostPageState extends State<PostPage> {
  DateTime lastPopTime; //上次点击时间
  int tabIndex = 0;

  _getHeaderWidge() {
    return Container(
      color: Color(0xff2296f3),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          GestureDetector(
            child: Tooltip(
              child: Icon(
                Icons.search,
                color: Colors.white,
              ),
              message: '搜索',
            ),
            onTap: () {
              Navigator.pushNamed(context, '/search');
            },
          ),
          _tabItem('帖子', 0),
          _tabItem('医生', 1)
        ],
      ),
      height: 50,
      padding: EdgeInsets.only(right: 70),
    );
  }

  _tabItem(String text, int index) {
    return GestureDetector(
      child: Text(text,
          style: TextStyle(
              color: tabIndex == index
                  ? Colors.white
                  : Colors.white.withOpacity(0.6),
              fontSize: 20)),
      onTap: () {
        setState(() {
          tabIndex = index;
        });
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        title: _getHeaderWidge(),
      ),
      backgroundColor: Colors.grey[100],
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
            return new EditPost();
          }));
        },
        child: Icon(Icons.add),
        tooltip: "增加帖子",
      ),
      body: tabIndex == 0 ? PostList() : DoctorList(),
    );
  }
}
